import platform = require('../../../../platform/common/baseCommon');
import appClient = require('../../../../platform/client/appClient');

let moduleName = "platform.test";

/**
 * 数据服务测试视图
 */
@platform.addon("数据服务测试视图", "数据服务测试视图", moduleName)
@appClient.template('project/test/views/test/dbTest.html')
export class dbTestView extends appClient.baseView {

    $asyncDBTest?: JQuery = undefined;

    $asyncProxyDBTest?: JQuery = undefined;

    $result?: JQuery = undefined;

    $resultTitle?: JQuery = undefined;

    $errorTest?: JQuery = undefined;
    $infoTest?: JQuery = undefined;
    $warnTest?: JQuery = undefined;

    onAfterBind?() {
        this.$asyncDBTest.click(() => {
            appClient.asyncJsonCall("http://localhost:3000/remoteCall",
                "example",
                "query",
                ["cmd_dj_nsrxx", {}],
                (result) => {
                    console.log(platform.addonSerialize(result));
                    this.$resultTitle.text(`没有Where条件结果集`)
                    this.$result.text(platform.addonSerialize(result));
                },
                (error) => {
                    this.$result.text(error.message);
                });
        });

        this.$asyncProxyDBTest.click(() => {
            let factoy = <platform.IDataService>new appClient.remoteFactory(platform.IDataService, "remoteCall", "example").getValue();
            try {
                let result = factoy.query("cmd_dj_nsrxx", {});//
                this.$resultTitle.text(`有Where条件结果集`)
                this.$result.text(platform.addonSerialize(result));
            } catch (error) {
                this.$result.text(error);
            }
        });

        this.$infoTest.click(() => {
            appClient.alerts("消息标题", "消息提示!消息提示!");
        });
        this.$errorTest.click(() => {
            appClient.alerts("错误标题", "错误提示!错误提示!", appClient.alertType.error);
        });
        this.$warnTest.click(() => {
            appClient.alerts("警告标题", "警告提示!警告提示!", appClient.alertType.warning);
        });
    }
}